@echo off
echo ========================================
echo 完全重新编译和打包插件
echo ========================================

echo.
echo [1/6] 删除 webview_ui 缓存和编译结果...
cd webview_ui
if exist .vite rmdir /s /q .vite
if exist dist rmdir /s /q dist
if exist node_modules\.vite rmdir /s /q node_modules\.vite
cd ..

echo.
echo [2/6] 编译 webview_ui...
cd webview_ui
call npm run build
if %ERRORLEVEL% NEQ 0 (
    echo 错误: webview编译失败！
    pause
    exit /b 1
)
cd ..

echo.
echo [3/6] 编译 TypeScript 后端...
call npm run compile
if %ERRORLEVEL% NEQ 0 (
    echo 错误: TS编译失败！
    pause
    exit /b 1
)

echo.
echo [4/6] 复制资源文件...
node scripts/copy-resources.js

echo.
echo [5/6] 删除旧的 vsix...
if exist harmonypilot-0.2.4.vsix del /f harmonypilot-0.2.4.vsix

echo.
echo [6/6] 打包插件...
call npx vsce package --allow-missing-repository
if %ERRORLEVEL% NEQ 0 (
    echo 错误: 打包失败！
    pause
    exit /b 1
)

echo.
echo ========================================
echo ✅ 编译完成！
echo ========================================
echo.
echo 插件文件: harmonypilot-0.2.4.vsix
echo.
echo 安装命令:
echo code --install-extension harmonypilot-0.2.4.vsix --force
echo.
pause


